package com.goddess.yeecolor.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;

import com.amap.api.maps.AMap;
import com.amap.api.maps.MapView;
import com.amap.api.maps.model.BitmapDescriptorFactory;
import com.amap.api.maps.model.LatLng;
import com.amap.api.maps.model.Marker;
import com.amap.api.maps.model.MarkerOptions;
import com.goddess.yeecolor.R;
import com.goddess.yeecolor.base.BaseActivity;

/**
 * 地图
 */
public class ExerciseMapActivity extends BaseActivity implements AMap.InfoWindowAdapter{
    private MapView mMapView=null;
    private Toolbar mToobar;
    private TextView mTitle;
    private String ln,la,title;
    private AMap aMap;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        setTheme(R.style.AppTheme);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_map);
        mMapView = (MapView) findViewById(R.id.mapview);
        /**
         * 创建地图
         */
        mMapView.onCreate(savedInstanceState);// 此方法必须重写
        /**
         * 获取位置
         */
        Bundle bundle=getIntent().getBundleExtra("bundle");
        ln=bundle.getString("ln");
        la=bundle.getString("la");
        title=bundle.getString("title");


        if (aMap == null) {
            aMap = mMapView.getMap();
            aMap.setInfoWindowAdapter(this);
            setLoction();
        }
        initFindView();
    }

    @Override
    public void initOnClck() {

    }

    @Override
    public void initFindView() {
        mToobar= (Toolbar) findViewById(R.id.title_toobar);
        mTitle= (TextView) findViewById(R.id.title_content);
        mToobar.setNavigationIcon(R.mipmap.back3x);
        mToobar.setNavigationOnClickListener((view)->{
            setFiish(this);
        });
    }

    @Override
    public void initData() {

    }


    @Override
    protected void onStop() {
        super.onStop();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        //在activity执行onDestroy时执行mMapView.onDestroy()，销毁地图
        mMapView.onDestroy();
    }

    @Override
    protected void onResume() {
        super.onResume();
        //在activity执行onResume时执行mMapView.onResume ()，重新绘制加载地图
        mMapView.onResume();
    }
    @Override
    protected void onPause() {
        super.onPause();
        //在activity执行onPause时执行mMapView.onPause ()，暂停地图的绘制
        mMapView.onPause();
    }
    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        //在activity执行onSaveInstanceState时执行mMapView.onSaveInstanceState (outState)，保存地图当前的状态
        mMapView.onSaveInstanceState(outState);

    }


    /**
     * 设置位置
     */
    private MarkerOptions markerOption;
    private Marker marker;
    private void setLoction(){
        /**
         * 设置经纬度
         */
        LatLng latLng = new LatLng(Double.valueOf(la).doubleValue(),Double.valueOf(ln).doubleValue());
        markerOption = new MarkerOptions().icon(BitmapDescriptorFactory
                .defaultMarker(BitmapDescriptorFactory.HUE_MAGENTA))
                .position(latLng)
                .snippet(title+"")
                .draggable(true);

        aMap.addMarker(markerOption);

        marker=aMap.addMarker(markerOption);
        marker.showInfoWindow();
    }

    /**
     * 定义 Marker 点击事件监听
     */
    AMap.OnMarkerClickListener  markerClickListener=new AMap.OnMarkerClickListener() {
        @Override
        public boolean onMarkerClick(Marker marker) {
            return false;
        }
    };
    View infoWindow = null;
    /**
     * 监听自定义infowindow窗口的infowindow事件回调
     */
    @Override
    public View getInfoWindow(Marker marker) {
        if (infoWindow==null){

        }
        return null;
    }

    @Override
    public View getInfoContents(Marker marker) {
        return null;
    }
}
